home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / drgnsmth.cpt / Dragonsmith 1.1 / Base files / Utilities / GestaltUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-11  |  1.8 KB  |  86 lines

  1. /*
  2.     GestaltUtils.c
  3.     
  4.     Created    17 Sep 1992    GestaltBatchCheck and GestaltResultOK
  5.     Modified    
  6.  
  7.     Copyright ⌐ 1992 by Paul M. Hoffman
  8.     Send comments or suggestions to paul.hoffman@um.cc.umich.edu
  9.     
  10.     This source code may be freely used, altered, and distributed in any way as long as:
  11.         1.    It is GIVEN away rather than sold (except as expressly permitted by the author)
  12.         2.    This statement and the above copyright notice are left intact.
  13.  
  14. */
  15.  
  16. #include    "GestaltUtils.h"
  17.  
  18. OSErr GestaltBatchCheck (GstCheckList **checkList)
  19. {
  20.     short            n, i;
  21.     GstCheckRec        *checkp;
  22.     OSErr            err = noErr;
  23.     
  24.     if (checkList == NULL || *checkList == NULL)
  25.         return nilHandleErr;
  26.         
  27.     n = (*checkList)->numChecks;
  28.     if (n < 0)
  29.         return nilHandleErr;        // Assume that something bad has happened
  30.     else if (n == 0)
  31.         return noErr;
  32.     
  33.     HLock ((Handle) checkList);
  34.     
  35.     for (i = 0, checkp = (*checkList)->check; i < n; i++, checkp++) {
  36.         if (GestaltResultOK (checkp->selector, checkp->compOp, checkp->compValue) == FALSE) {
  37.             err = checkp->failureError;
  38.             break;
  39.         }
  40.     }
  41.     
  42.     HUnlock ((Handle) checkList);
  43.     
  44.     return err;
  45. }
  46.  
  47. Boolean GestaltResultOK (OSType selector, short compOp, long compValue)
  48. {
  49.     OSErr    err;
  50.     long        result;
  51.     
  52.     err = Gestalt (selector, &result);
  53.     if (err != noErr)
  54.         return FALSE;
  55.     
  56.     switch (compOp) {
  57.         case opBitAnd:
  58.             return (result & compValue == compValue);
  59.             break;
  60.         case opEqual:
  61.             return (result == compValue);
  62.             break;
  63.         case opNotEqual:
  64.             return (result != compValue);
  65.             break;
  66.         case opGreater:
  67.             return (result > compValue);
  68.             break;
  69.         case opGreaterOrEqual:
  70.             return (result >= compValue);
  71.             break;
  72.         case opLess:
  73.             return (result < compValue);
  74.             break;
  75.         case opLessOrEqual:
  76.             return (result <= compValue);
  77.             break;
  78.         case opNoErrIsOK:
  79.             return TRUE;
  80.             break;
  81.         default:
  82.             return FALSE;
  83.     }
  84. }
  85.  
  86.